import java.util.*;
import java.io.*;

import org.jfree.ui.RefineryUtilities;

public class PIDGraph
{
	private static LinkedList <PIDRecord> records;
	
	private static double velocity;
	private static int displacement;
	private static double [] constants;
	
	private static double [][] 	phase,
								currentVelocity,
								targetVelocity,
								pidOutput,
								currentDisplacement,
								motorOutput;

	public static void main ( String [] args )
	{	
		fillArrays();
		
		plotGraph();
	}
	
	
	private static void fillArrays ()
	{
		Scanner scan = null;
		File file = new File ( "pidrecord.txt" );
		
		try									{	scan = new Scanner ( file );	}
		catch ( FileNotFoundException e )	{	e.printStackTrace();	}
		
		records = new LinkedList <PIDRecord> ();
		scan.useDelimiter(", ");
		
		velocity = scan.nextDouble();
		displacement = scan.nextInt();
		constants = new double [9];
		for ( int i=0; i<9; i++ )
			constants[i] = scan.nextDouble();
		
		while ( scan.hasNext() )
		{
			double temp1, temp2, temp3, temp4, temp5, temp6;
			temp1 = scan.nextInt();
			temp2 = scan.nextDouble();
			temp3 = scan.nextDouble();
			temp4 = scan.nextDouble();
			temp5 = scan.nextInt();
			temp6 = scan.nextDouble();
			
			records.add( new PIDRecord( temp1, temp2, temp3, temp4, temp5, temp6 ) );
		}
		
		int recordsSize = records.size();
		phase = new double [2][recordsSize];
		currentVelocity = new double [2][recordsSize];
		targetVelocity = new double [2][recordsSize];
		pidOutput = new double [2][recordsSize];
		currentDisplacement = new double [2][recordsSize];
		motorOutput = new double [2][recordsSize];
		
		for ( int i=0; i<recordsSize; i++ )
		{
			phase[0][i] = i;
			phase[1][i] = records.get(i).phase;
			
			currentVelocity[0][i] = i;
			currentVelocity[1][i] = records.get(i).currentVelocity;
			
			targetVelocity[0][i] = i;
			targetVelocity[1][i] = records.get(i).targetVelocity;
			
			pidOutput[0][i] = i;
			pidOutput[1][i] = records.get(i).pid;
			
			currentDisplacement[0][i] = i;
			currentDisplacement[1][i] = records.get(i).currentDisplacement;
			
			motorOutput[0][i] = i;
			motorOutput[1][i] = records.get(i).motorOutput;
		}
	}

	private static void plotGraph ()
	{
		CombinedGraph graph = new CombinedGraph ( velocity, displacement, constants, phase, currentVelocity, targetVelocity, pidOutput, currentDisplacement, motorOutput );
		graph.pack();
		RefineryUtilities.centerFrameOnScreen( graph );
		graph.setVisible( true );
	}
}



class PIDRecord
{
	double phase, currentVelocity, targetVelocity, pid, currentDisplacement, motorOutput;
	
	PIDRecord( double phase, double currentVelocity, double targetVelocity, double pid, double currentDisplacement, double motorOutput )
	{
		this.phase = phase;
		this.currentVelocity = currentVelocity;
		this.targetVelocity = targetVelocity;
		this.pid = pid;
		this.currentDisplacement = currentDisplacement;
		this.motorOutput = motorOutput;
	}
}